package org.hyh.autowired;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @auther :hyh
 * @desc :
 * @date :2019/12/5
 */
@Configuration
@Component
@Aspect
@EnableAspectJAutoProxy(exposeProxy = true)
public class TestAOP {

	@Pointcut("@annotation(org.hyh.autowired.TestAdmin)")
	public  void  pointCut() {

	}

	@Before("pointCut()")
	public  void  testBefore(JoinPoint joinPoint) throws InvocationTargetException, IllegalAccessException {
		System.out.println("@before");
	}

	@After("pointCut()")
	public  void  testAfter(JoinPoint joinPoint) throws InvocationTargetException, IllegalAccessException {

		System.out.println("@After");
	}

	@AfterReturning(value = "pointCut()",returning = "abc")
	public  void  testAfterReturning(JoinPoint joinPoint,String abc) throws InvocationTargetException, IllegalAccessException {

		MethodSignature signature  = (MethodSignature) joinPoint.getSignature();
		Method method = signature.getMethod();
		System.out.println(method.getName()+"==>@AfterReturning");
	}


	@AfterThrowing("pointCut()")
	public  void  testAfterThrowing(JoinPoint joinPoint) throws InvocationTargetException, IllegalAccessException {

		System.out.println("@AfterThrowing");
	}



}
